﻿using FakeXiecheng.API.Dtos;
using System.ComponentModel.DataAnnotations;

namespace FakeXiecheng.API.ValidationAttributes
{
    /// <summary>
    /// DTO的类级别 数据验证
    /// </summary>
    public class TouristRouteDTOTitleMustDifferentFromDescription : ValidationAttribute
    {
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            var touristRouteDTO = (TouristRouteValidataDTO)validationContext.ObjectInstance;
            if (touristRouteDTO.Title == touristRouteDTO.Description)
            {
                return new ValidationResult(
                    "路线Title必须与路线Description不一致！"//错误信息
                    , new[] { "TouristRouteForCreateDTO" });//错误路径
            }

            return ValidationResult.Success;
        }
    }
}
